<template>
    <div class="baranch">
        <el-row size="mini">
            <el-col :span="12" class="col-wrap">
                <el-row class="border-box">
                    <el-col :span="12" class="search-wrap">
                        <el-input size="mini" disabled v-model="calculateShowLogic" :title="calculateShowLogic"></el-input>
                    </el-col>
                    <!-- <el-col :span="7" class="search-wrap">
                        <el-select placeholder="请选择分支模板" size="mini" style="width:100%" clearable v-model="entryBranch.templateCode">
                            <el-option
                                v-for="(item, index) in templateDataSource"
                                :key="index"
                                :label="item.templateCode + ' ' + item.templateName"
                                :value="item.templateCode"
                                :disabled="['2', '3'].includes(item.modifyType)"
                            >
                            </el-option>
                        </el-select>
                    </el-col> -->
                    <!-- <el-col :span="3" class="search-wrap">
                        <el-button style="float:right" size="mini" type="primary" @click="handleAddTemplate">添加</el-button>
                    </el-col>
                    <el-col :span="1" class="search-wrap">
                        <el-button size="mini" icon="el-icon-refresh-right" type="primary"></el-button>
                    </el-col> -->
                </el-row>
                <el-row class="border-box">
                    <el-col :span="6" class="search-wrap">
                        <el-select placeholder="请选择" size="mini" style="width: 100%" clearable v-model="entryBranch.countType">
                            <el-option
                                v-for="item in countTypeList"
                                :key="item.dictKey"
                                :label="item.dictKey + ' ' + item.dictKeyName"
                                :value="item.dictKey"
                            ></el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="10" class="search-wrap">
                        <el-select
                            name="计算因子"
                            placeholder="请选择"
                            size="mini"
                            style="width: 100%"
                            clearable
                            filterable
                            v-model="entryBranch.factorCode"
                            @change="changBranchName($event)"
                        >
                            <el-option
                                v-for="item in calcFactorList"
                                :key="item.entryCalculateFactorCode"
                                :title="item.entryCalculateFactorCode + ' ' + item.entryCalculateFactorName"
                                :label="item.entryCalculateFactorCode + ' ' + item.entryCalculateFactorName"
                                :value="item.entryCalculateFactorCode"
                                :name="'calc' + item.entryCalculateFactorCode"
                            ></el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="6" class="search-wrap">
                        <el-input
                            name="分支名称"
                            placeholder="请输入分支名称"
                            size="mini"
                            v-model="entryBranch.branchName"
                            :title="entryBranch.branchName"
                        ></el-input>
                    </el-col>
                    <el-col :span="2" class="search-wrap">
                        <el-button
                            icon="el-icon-circle-plus-outline"
                            name="addCalc"
                            size="mini"
                            type="primary"
                            title="添加"
                            @click="handleAddConfig"
                        ></el-button>
                    </el-col>
                </el-row>
                <el-row class="border-box">
                    <el-col :span="22" class="search-wrap">
                        <div class="tree-box">
                            <el-tree
                                size="mini"
                                ref="tree"
                                id="tree"
                                default-expand-all
                                :data="entryBranchConfigTree"
                                :props="defaultProps"
                                @node-click="onSelectConfigTree"
                                node-key="branchNo"
                                :expand-on-click-node="false"
                            >
                                <!-- 模板中没有设置动态配置？ -->
                            </el-tree>
                        </div>
                    </el-col>
                    <el-col :span="2" class="search-wrap">
                        <el-button name="saveCalc" size="mini" icon="el-icon-check" title="保存" @click="handleSaveConfig"></el-button>
                        <div style="margin-top: 10px">
                            <el-button
                                size="mini"
                                icon="el-icon-minus"
                                type="danger"
                                name="delCalc"
                                title="删除配置"
                                @click="handleDelConfig"
                            ></el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-col>

            <!-- 范围 -->
            <el-col :span="12" class="search-wrap">
                <el-row class="border-box">
                    <el-col :span="5" class="search-wrap">
                        <el-select
                            placeholder="范围属性"
                            name="范围属性"
                            size="mini"
                            style="width: 100%"
                            v-model="investGroupTypeValue"
                            @change="changInvestType"
                        >
                            <el-option
                                v-for="item in optionalInvestGroupType"
                                :key="item"
                                :label="BoundType[item]"
                                :title="BoundType[item]"
                                :value="item"
                                :name="BoundType[item]"
                            ></el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5" class="search-wrap" v-show="investGroupTypeValue == '3'">
                        <el-select
                            placeholder="请选择"
                            size="mini"
                            style="width: 100%"
                            filterable
                            multiple
                            collapse-tags
                            v-model="category"
                            @change="changeCategory(category)"
                        >
                            <el-option label="-1 全部" value="-1" :disabled="Category"></el-option>
                            <el-option
                                v-for="item in categorys"
                                :disabled="CategoryAll"
                                :key="item.dictKey"
                                :label="item.dictKey + ' ' + item.dictKeyName"
                                :value="item.dictKey"
                                :title="item.dictKey + ' ' + item.dictKeyName"
                            ></el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="4" class="search-wrap">
                        <el-select
                            name="boundTemp"
                            placeholder="选择范围模板"
                            size="mini"
                            style="width: 100%"
                            v-model="templateCode"
                            title="选择范围模板"
                            filterable
                        >
                            <el-option
                                v-for="item in BranchDataSource"
                                :key="item.templateCode"
                                :label="item.templateCode + ' ' + item.templateName"
                                :value="item.templateCode"
                                :disabled="['2', '3'].includes(item.modifyType)"
                                :name="'boundTemp-' + item.templateCode"
                            ></el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5" class="search-wrap">
                        <el-button name="boundTempAdd" size="mini" type="primary" @click="handleAddTemplateR">添加</el-button>
                    </el-col>
                    <el-col :span="3" class="search-wrap">
                        <el-button name="范围预览" size="mini" style="float: right" type="primary" @click="lookBranchData">范围预览</el-button>
                    </el-col>
                    <el-col :span="1" class="search-wrap">
                        <el-button
                            name="refreshBound"
                            size="mini"
                            icon="el-icon-refresh-right"
                            type="primary"
                            title="刷新"
                            @click="refreshAllBranchTemplate"
                        ></el-button>
                        <!-- <el-button size="mini" icon="el-icon-refresh-right" type="primary" title="刷新"></el-button> -->
                    </el-col>
                </el-row>
                <el-row class="border-box">
                    <el-col :span="4" class="search-wrap">
                        <el-select name="sqlSpliceType" v-model="sqlSpliceType" placeholder="请选择" size="mini" @change="handleSqlSpliceType">
                            <el-option
                                v-for="(value, key) in conditionRelation"
                                :key="key"
                                :label="key + ' ' + value"
                                :value="key + ' ' + value"
                                :name="'sqlSpliceType' + key"
                            >
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5" class="search-wrap">
                        <el-select
                            name="证券范围"
                            v-model="fundDynamicGroupBounds.boundCode"
                            placeholder="证券范围"
                            filterable
                            @change="handleOriginalBoundConfig"
                            size="mini"
                        >
                            <el-option value="-1" label=" " key="-1"></el-option>
                            <el-option
                                v-for="item in originList"
                                :key="item.boundCode"
                                :label="item.boundCode + '' + item.boundName"
                                :value="item.boundCode"
                                :name="'bound' + item.boundCode"
                            >
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="5" class="search-wrap">
                        <el-select name="比较方向" v-model="fundDynamicGroupBounds.compareType" placeholder="比较方向" size="mini">
                            <el-option
                                v-for="value in compareTypes"
                                :key="value"
                                :label="value + '  ' + CompareDirection[value]"
                                :value="value"
                                :name="'compareType' + value"
                            >
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="4" class="search-wrap">
                        <div v-show="webShowType === '0'">
                            <vxe-pulldown ref="showTypeDown">
                                <template #default>
                                    <yh-input
                                        name="下拉多选框"
                                        v-model="boundValueShow"
                                        placeholder="请选择"
                                        @focus="showTypeFocusEvent"
                                        class="service-type-input"
                                        size="mini"
                                    ></yh-input>
                                </template>
                                <template #dropdown>
                                    <div class="my-dropdown" style="width: 200px">
                                        <div class="accountControlValue-search">
                                            <i class="el-icon-search" style="cursor: pointer"></i>
                                            <yh-input
                                                v-model="boundValueSearchInput"
                                                @keyup.native="boundValueSearch"
                                                placeholder="请选择"
                                                size="mini"
                                            ></yh-input>
                                        </div>
                                        <div>
                                            <yh-checkbox-group v-model="fundDynamicGroupBounds.boundValues" @change="handleBoundValueChange">
                                                <yh-checkbox
                                                    v-for="item in dictsTemp"
                                                    :key="item.dictKey"
                                                    :label="item.dictKey"
                                                    :name="'boundValues' + item.dictKey"
                                                >
                                                    {{ item.dictKey + '  ' + item.dictKeyName }}</yh-checkbox
                                                >
                                            </yh-checkbox-group>
                                        </div>
                                    </div>
                                </template>
                            </vxe-pulldown>
                        </div>
                        <!-- 计数器-整数 -->
                        <yh-input-number
                            name="计数器-整数"
                            v-model="form.boundValueNum"
                            controls-position="right"
                            @change="handleBoundValueChange1"
                            :step="1"
                            v-if="webShowType === '1'"
                            size="mini"
                        ></yh-input-number>
                        <div v-show="webShowType === '2' && !separateValid" style="display: flex">
                            <el-input
                                name="大数据穿梭框"
                                disabled
                                style="width: 80px"
                                size="mini"
                                placeholder=""
                                v-model="transValuesShow"
                                :title="transValuesShow"
                            ></el-input>
                            <el-button
                                name="大数据穿梭框按钮"
                                type="primary"
                                icon="el-icon-search"
                                size="mini"
                                @click="selectKeyValue2Click"
                                style="margin-left: 2px"
                            >
                            </el-button>
                        </div>
                        <el-date-picker
                            name="日期时间"
                            v-model="boundValueDate"
                            type="date"
                            placeholder="选择日期时间"
                            size="mini"
                            value-format="yyyyMMdd"
                            format="yyyyMMdd"
                            v-show="webShowType === '3'"
                        >
                            <!--  @change="handleBoundValueChange2" -->
                        </el-date-picker>
                        <el-select
                            name="下拉单选"
                            v-model="boundValueSelect"
                            v-show="webShowType === '4'"
                            @change="handleBoundValueChange3"
                            size="mini"
                        >
                            <el-option
                                v-for="item in dictsTemp"
                                :key="item.dictKey"
                                :label="item.dictKey + ' ' + item.dictKeyName"
                                :value="item.dictKey"
                                :name="'boundValue' + item.dictKey"
                            >
                            </el-option>
                        </el-select>
                        <!-- 计数器-小数 -->
                        <el-input-number
                            name="计数器-小数"
                            v-model="form.boundValueNum"
                            controls-position="right"
                            :disabled="showData"
                            :step="1"
                            :precision="6"
                            :max="10000000000000"
                            @change="handleBoundValueChange1"
                            v-if="webShowType === '5'"
                            size="mini"
                        ></el-input-number>
                    </el-col>
                    <el-col :span="4" class="search-wrap">
                        <el-checkbox
                            name="单独控制"
                            size="mini"
                            v-model="separateValid"
                            :disabled="!currentConfigSeparateValid"
                            @change="changSeparateValid"
                            style="margin-top: 4px"
                            >单独控制</el-checkbox
                        >
                    </el-col>
                    <el-col :span="2" class="search-wrap">
                        <el-button
                            name="boundAdd"
                            size="mini"
                            icon="el-icon-circle-plus-outline"
                            @click="handleAddConfigRight"
                            title="添加"
                            type="primary"
                        ></el-button>
                    </el-col>
                </el-row>
                <el-row class="border-box">
                    <el-col :span="22" class="search-wrap">
                        <div class="tree-box">
                            <el-tree
                                ref="tree2s"
                                id="tree"
                                default-expand-all
                                :data="originalRenderTreeShow"
                                :props="defaultProps"
                                @node-click="handleBoundNodeClick"
                                :expand-on-click-node="false"
                                node-key="configId"
                                :check-on-click-node="true"
                            >
                                <span class="custom-tree-node" slot-scope="{ node, data }">
                                    <span :name="node.label">{{ node.label }}</span>
                                    <i
                                        :class="'boundExtend' + data.boundCode"
                                        class="el-icon-setting"
                                        style="font-size: 20px; color: orange; margin-left: 3px"
                                        :style="{ display: data.showBoundExtend ? '' : 'none' }"
                                        @click.stop="handeBoundExtend(data)"
                                    />
                                    <ItemBoundExtendModel
                                        :showModal="showBoundExtendModel"
                                        :selectWebSqlValues="selectWebSqlValues5"
                                        :boundConfigExtends="boundConfigExtends"
                                        :record="FiveData"
                                        :resolveKey="resolveKey"
                                        @handleBoundExtendModel="handleBoundExtendModel"
                                        v-if="showBoundExtendModel"
                                    ></ItemBoundExtendModel>
                                </span>
                            </el-tree>
                        </div>
                    </el-col>
                    <el-col :span="2" class="search-wrap">
                        <el-button size="mini" icon="el-icon-check" title="编辑" @click="handleUpdateConfig" type="primary"></el-button>
                        <div style="margin-top: 10px">
                            <el-button
                                name="boundDel"
                                size="mini"
                                icon="el-icon-minus"
                                type="danger"
                                title="删除配置"
                                @click="handleDeleteConfig"
                            ></el-button>
                        </div>
                        <!-- <div style="margin-top:10px">
                            <el-button size="mini" icon="el-icon-warning" type="primary"></el-button>
                        </div> -->
                    </el-col>
                </el-row>
            </el-col>
        </el-row>
        <yh-dialog
            drag
            title="资产范围定位查找"
            :visible.sync="branchVisible"
            width="600px"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
        >
            <div>
                <el-input placeholder="请输入资产明细" v-model="searchValue" size="mini" style="width: 100%" @keyup.enter.native="searchBound">
                    <i slot="suffix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="searchBound"></i>
                </el-input>
                <el-table :data="dataSource" border size="mini" style="width: 100%; margin-top: 10px" height="360px" v-loading="loading">
                    <el-table-column label="范围类型" show-overflow-tooltip>
                        <template slot-scope="scope">
                            <span>
                                {{ scope.row.boundType }}
                                {{ BoundTypeList[scope.row.boundType] }}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column label="资产名称" show-overflow-tooltip>
                        <template slot-scope="scope">
                            <span>
                                {{ scope.row.boundCode }}
                            </span>
                            <span>
                                {{ scope.row.boundName }}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="boundType" label="资产明细" show-overflow-tooltip>
                        <template slot-scope="scope">
                            <span>
                                {{ scope.row.key || '' }}
                            </span>
                            <span>
                                {{ scope.row.name || '' }}
                            </span>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="block">
                    <risk-pagination :paging="boundPage" @page-change="boundPageChange"></risk-pagination>
                </div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button size="mini" @click="oepnDialog"> 取 消 </el-button>
            </div>
        </yh-dialog>
        <yh-dialog drag :visible.sync="editLargeDataDialog.visible" width="800px" class="editDialog">
            <div style="height: fit-content">
                <RiskSettingInline
                    :boundCode="fundDynamicGroupBounds.boundCode"
                    ref="trans"
                    url="/original/showBigData"
                    index-key="dictKey"
                    left-placeholder="编号/名称"
                    right-placeholder="编号/名称"
                    :columns="tranColumns"
                    :right-table-data="rightTranData"
                    :search-names="['dictKey', 'dictKeyName']"
                />
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button name="transCancel" size="mini" @click="editLargeDataDialog.visible = false"> 取 消 </el-button>
                <el-button name="transConfirm" size="mini" type="primary" @click="editLargeDataDialogConfirm">确 认 </el-button>
            </div>
        </yh-dialog>
    </div>
</template>
<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
import DictionConstUtil, { SGU_CACHE } from '@/utils/diction-const-util';
import { mixins } from 'vue-class-component';
import RiskEmitter from '@/common/mixis/risk-emitter.vue';
import XEUtils from 'xe-utils';
import { DialogVO } from '@yhfin/biz';
import Dict from '@/pages/baseparam/dict/index';
import RiskTrantable from '@/common/components/risk-trantable.vue';
import ItemBoundExtendModel from '@/pages/baseparam/fund-group-setting/item-bound-extend-model.vue';
import RiskSettingInline from '@/common/components/risk-setting-inline.vue';
import { FilterPanel } from 'vxe-table';
import RiskPagination from '@/common/components/risk-pagination.vue';

export interface pages {
    total?: number;
    pageSize?: number;
    currentPage?: number;
    totalPage?: number;
}

export interface dynamicDataReqVO {
    dynamicCode?: string;
    boundCode?: string;
    boundValues?: any[];
    compareType?: string; // 比较方向
    boundValueNames?: any[]; //
    boundGroupValid?: boolean; // 是否是组配置
    parentId?: number;
    configId?: number;
    children?: any[];
    webSqlType?: '';
    webBoundName?: '';
    webCompareType?: '';
    webBoundvalue?: '';
    webgroupType?: '';
    boundExtend?: ''; // 范围模板5额外配置字段
    separateValid?: boolean; // 是否同申报
    sqlSpliceType?: string; // sql拼接符
    groupType?: string; // 范围配置组控制类型
    showBoundExtend?: boolean;
}

@Component({
    name: 'ItemBranchSetting0',
    components: {
        RiskTrantable,
        ItemBoundExtendModel,
        RiskSettingInline,
        RiskPagination,
    },
})
export default class ItemBranchSetting0 extends mixins(RiskEmitter) {
    @Prop() riskEntryBranchList!: any[];
    templateDataSource: any[] = [];
    entryType: any = '0';
    calculateShowLogic: string = '';
    entryBranch: any = {
        templateCode: undefined, // 选择的模板序号
        countType: '0',
        factorCode: '',
        branchName: '',
        branchType: '',
        entryCode: '',
    };
    renderBoundCount: any = -1;
    countTypeList: any[] = [];
    calcFactorList: any[] = [];
    branchEnum: any = {};
    branchNo: any = 1;
    allParentTreeNodes: any[] = []; // 所有的父级节点 便于全部展开
    riskEntryBranchs: any[] = [];
    defaultProps = {
        children: 'children',
        label: 'label',
    };
    currentTreeNode: any = null;
    entryControl: any = {};
    showBoundExtend: boolean = false; // 是否展示第五类图标
    showBoundExtendModel: boolean = false; // 是否打开第五类弹框
    currentBoundExtend: any = {}; // 第五类当前节点数据
    selectWebSqlValues5: any[] = []; // 下拉列表可选值
    boundConfigExtends: any[] = []; // 下拉列表可选值
    currentOpenTreeNode: any[] = []; // 当前展开的节点
    entryBranchConfigTree: any[] = []; // 分支树数据
    currentSelectCalcFactor: any = {}; // 当前选择的计算因子

    /**
     * 范围定义字段
     */
    investGroupTypeValue: any = ''; // 投资属性设置选择值
    investGroupType: any = {}; // 设置默认的范围属性
    optionalInvestGroupType: any[] = []; // 可选属性投资范围
    optionalBound: any = []; // 计算因子可选的范围
    BoundType: any = {}; // 范围数组
    categorys: any[] = []; // 指标类型
    category: any = ['-1'];
    templateCode: any = null; // 选择范围模板
    BranchDataSource: any[] = []; // 可配置范围信息
    branchVisible: boolean = false; // 资产范围定位查找弹窗
    loading: boolean = false;
    searchValue: any = null; // 弹窗搜索
    dataSource: any[] = [
        {
            boundName: '',
        },
    ]; // 弹框表格
    boundPage: pages = {
        currentPage: 1,
        pageSize: 25,
        total: 0,
        totalPage: 0,
    };
    BoundTypeList: any = {}; // 获取范围类型数组
    riskEntryBranchsList: any[] = []; // 填加模板时候请求回来的数据
    clickIndex: any = 0; // 记录点击次数

    // 以下定义取bcf0的
    Dict: any = new Dict();
    sqlSpliceType: string = '0 并且';
    // sql拼接字段符转义
    conditionRelation: any = [];
    fundDynamicGroupBounds: dynamicDataReqVO = {
        // 证券范围配置项
        dynamicCode: '',
        boundCode: '-1',
        boundValues: [],
        children: [],
        compareType: '', // 比较方向
        boundValueNames: [], //
        boundGroupValid: true,
        parentId: 0,
        configId: 0,
        separateValid: false, // 是否同申报
        sqlSpliceType: '0', // sql拼接符
        groupType: '', // 范围配置组控制类型
    };
    compareTypes: any[] = []; // 比较类型
    webShowType: string = '5'; // 输入框类型
    boundValueShow: string = ''; // 多选框所选值回显
    boundValueSearchInput: string = ''; // 多选框搜索输入值
    dictsTemp = []; // 多选框临时选项
    dicts = []; // 多选框选项
    form = {
        boundValueNum: undefined, // 计数器输入框绑定值
    };
    transValuesShow: string = '';
    editLargeDataDialog: DialogVO = new DialogVO();
    leftTranData: any[] = [];
    rightTranData: any[] = [];
    tranColumns: any[] = [
        {
            label: '编号',
            prop: 'dictKey',
            width: 80,
        },
        {
            label: '名称',
            prop: 'dictKeyName',
            width: 165,
        },
    ];
    boundValueDate: string = ''; // 日期选择期绑定值
    boundValueSelect: string = ''; // 单选框绑定值
    separateValid: boolean = false; // 单独控制
    currentConfigSeparateValid: boolean = false; // 单独控制单选框是否禁用
    notShowSingleControl: boolean = true; // 单独控制单选框是否显示
    originalConfigList: any = []; // 配置数据集合
    stockBound: any = null;
    // 范围属性组
    originList: any = [];
    configId: number = 1;
    originalRenderTree: any[] = [];
    originalRenderTreeShow: any[] = [];
    CompareDirection = this.Dict.CompareDirection;
    currentTreeNodeR: any = null;
    allParentTreeNodeR: any = []; // 所有的父级节点 便于全部展开
    currentOpenTreeNodeR: any[] = []; // 当前展开的节点
    BoundCfgs: any[] = [];
    BranchData: any = [];
    OriginalBoundConfigPojo: any = {}; // 该对象为范围属性对应的范围集合 key=groupType，value=对象
    allParentTreeNodesR: any[] = [];
    //
    Category: boolean = false;
    CategoryAll: boolean = true;
    FiveData: any = {};
    resolveKey: string = '';

    created() {
        this.$on('setentryTypes', this.setEntryType);
    }

    async mounted() {
        // 计算标识符
        this.countTypeList = DictionConstUtil.PojoToList(DictionConstUtil.RiskEntryBranchSplicingType);
        // 获取可配置分支信息
        let DataSource = await DictionConstUtil.FNBranchTemplate();
        this.templateDataSource = DataSource.filter((item: any) => item.entryType === this.entryType);
        await this.getCalcFactor(this.entryType);

        // 指标类型
        this.categorys = await DictionConstUtil.FNCateGory();

        // 获取范围类型数组
        this.BoundTypeList = DictionConstUtil.BoundType;
        this.conditionRelation = this.Dict.conditionRelation;
        // 配置数据集合
        this.originalConfigList = JSON.parse(JSON.stringify(this.stockBound || []));
        // 获取范围配置信息
        this.BoundCfgs = await DictionConstUtil.FNBoundCfg();
        this.BranchData = await DictionConstUtil.FNBranchBoundTemplate();
        // this.originList = this.BoundCfgs.filter((item: any) => item.validSymbol === '1').sort(
        //     (a, b) => a.boundCode.replace(/[^0-9]/gi, '') - b.boundCode.replace(/[^0-9]/gi, '')
        // );
    }
    // 深度监听传过来的数据 如果有数据就渲染上去
    @Watch('riskEntryBranchList', { immediate: true, deep: true })
    watchRiskEntryBranchList() {
        let templateBranch = JSON.parse(JSON.stringify(this.riskEntryBranchList));
        // 当前选择的树节点
        let currentTreeNode = this.currentTreeNode ? parseInt(this.currentTreeNode) : null;
        let factor = this.searchBranchConfig(currentTreeNode, 'entryBranch');
        // 获取下一分序号
        let branchNo = this.branchNo - 1;
        // 判断添加节点位置
        if (currentTreeNode && factor.branchType === '1') {
            for (let i = 0; i < templateBranch.length; i++) {
                templateBranch[i].entryBranch.branchNo += branchNo;
                templateBranch[i].entryBranch.label =
                    DictionConstUtil.RiskEntryBranchSplicingType[templateBranch[i].entryBranch.countType] +
                    ' ' +
                    (templateBranch[i].entryBranch.branchName || '');
                if (templateBranch[i].entryBranch.parentBranchNo === 0) {
                    templateBranch[i].entryBranch.parentBranchNo = currentTreeNode;
                } else {
                    templateBranch[i].entryBranch.parentBranchNo += branchNo;
                }
                this.branchNo = templateBranch[i].entryBranch.branchNo;
            }
        } else {
            for (let i = 0; i < templateBranch.length; i++) {
                templateBranch[i].entryBranch.branchNo += branchNo;
                templateBranch[i].entryBranch.label =
                    DictionConstUtil.RiskEntryBranchSplicingType[templateBranch[i].entryBranch.countType] +
                    ' ' +
                    (templateBranch[i].entryBranch.branchName || '');
                if (templateBranch[i].entryBranch.parentBranchNo === 0) {
                } else {
                    templateBranch[i].entryBranch.parentBranchNo += branchNo;
                }
                this.branchNo = templateBranch[i].entryBranch.branchNo;
            }
        }
        // this.branchNo += 1;
        this.riskEntryBranchs = this.riskEntryBranchs.concat(templateBranch);
        let riskEntryBranchs = JSON.parse(JSON.stringify(this.riskEntryBranchs));
        let newList = this.createTreeAdoptList(riskEntryBranchs, 0);
        // 执行配置公式生成方式
        this.calculateShowLogic = this.verifyBranchConfig(newList);
        // 节点渲染 默认展开所有的节点
        this.entryBranchConfigTree = this.createRenderTree(newList, '');
        this.$emit('set-branch-data', this.riskEntryBranchs);
    }
    // 父组件风险类型传过来的参数
    async setEntryType(val: any) {
        this.entryType = val;
        if (this.entryBranchConfigTree.length > 0) {
            this.$notify({
                title: '提示',
                message: '分支设置已清空，请重新设置',
                type: 'warning',
            });
            this.entryBranchConfigTree = [];
            this.currentOpenTreeNode = [];
            this.riskEntryBranchs = [];
            this.currentSelectCalcFactor = {};
            this.entryBranch = {
                branchName: '',
                factorCode: '',
                countType: '0',
                branchType: '',
                entryCode: '',
            };
            this.currentTreeNode = '';
        }
        this.getCalcFactor(this.entryType);
    }

    // 获取计算因子信息
    async getCalcFactor(entryType: any) {
        let funDatas = await DictionConstUtil.FNCalculateFactor();
        let res = funDatas
            .filter((item: any) => item.validSymbol === '1')
            .sort((a: any, b: any) => a.entryCalculateFactorCode.replace(/[^0-9]/gi, '') - b.entryCalculateFactorCode.replace(/[^0-9]/gi, ''));
        this.calcFactorList = res.filter((item: any) => item.entryTypes.includes(entryType));
        // 标识计算因子变动事件
        this.renderBoundCount = this.renderBoundCount + 1;
        this.entryBranch.branchName = '';
        // 设置计算因子枚举 以便查找
        let branchEnum = {};
        for (let i = 0; i < res.length; i++) {
            branchEnum[res[i].entryCalculateFactorCode] = res[i];
        }
        if (!branchEnum['-1']) {
            branchEnum['-1'] = '';
        }
        this.branchEnum = branchEnum;
    }

    // 第五类数据处理
    async handeBoundExtend(item) {
        this.FiveData = item;
        if (item.showBoundExtend) {
            await this.handleShowWebShow5(item.boundCode);
            await this.handleShowCompare(item.boundCode);
        }
        setTimeout(() => {
            this.showBoundExtendModel = true;
        }, 500);
        this.currentBoundExtend = item;
    }

    /**
     * 根据证券范围配置编号获取范围模板5比较反向
     */
    handleShowCompare(boundCode) {
        this.$axios.get('/original/showCompare/' + boundCode).then(
            (res: any) => {
                if (res) {
                    // res.values.forEach((item) => item.key = item.dictKey)
                    this.boundConfigExtends = res;
                }
            },
            () => {
                this.boundConfigExtends = [];
            }
        );
    }

    /**
     * 根据证券范围配置编号获取范围模板5 展示SQL
     */
    handleShowWebShow5(boundCode) {
        this.$axios.get('/original/showSelect5/' + boundCode).then(
            (res: any) => {
                if (res) {
                    // res.values.forEach((item) => item.key = item.dictKey)
                    this.selectWebSqlValues5 = res;
                }
            },
            () => {
                this.selectWebSqlValues5 = [];
            }
        );
    }

    /**
     * 范围5 额外配置回调
     * @param {*} action 行为
     * @param {*} configId  范围配置分支id
     * @param {*} value 范围额外配置 boundExtend
     */
    handleBoundExtendModel({ action, configId, value }): void {
        if (action === 'confirm') {
            this.OriginalBoundConfigPojo[this.investGroupTypeValue].children.forEach(item => {
                if (item.boundCode === this.currentBoundExtend.boundCode && item.configId == configId) {
                    item.boundExtend = value;
                    return;
                }
            });
            this.showBoundExtendModel = false;
            this.currentBoundExtend = {};
            this.originalRenderTree = this.handleGetRenderTree(this.OriginalBoundConfigPojo[this.investGroupTypeValue]);
            this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);
            // //回调函数
            this.onHandleSettingValue();
        } else if (action === 'cancel') {
            this.showBoundExtendModel = false;
        }
    }

    // 添加tree节点
    handleAddConfig(): void {
        if (!this.verifyBranchConfig1()) {
            return;
        }
        this.branchNo += 1;
        // 当前选择的树节点
        let currentTreeNode = this.currentTreeNode ? parseInt(this.currentTreeNode) : null;
        let factor = this.searchBranchConfig(currentTreeNode, 'entryBranch');
        let entryBranch: any = {};
        if (currentTreeNode && factor.branchType === '1') {
            entryBranch = this.createDynamicConfigPO(currentTreeNode);
        } else {
            entryBranch = this.createDynamicConfigPO(0);
        }
        this.riskEntryBranchs.push({ entryBranch: entryBranch, entryBranchConfigs: [] });
        let riskEntryBranchs = JSON.parse(JSON.stringify(this.riskEntryBranchs));
        let newList = this.createTreeAdoptList(riskEntryBranchs, 0);
        // 执行配置公式生成方式
        this.calculateShowLogic = this.verifyBranchConfig(newList);
        // 节点渲染
        this.entryBranchConfigTree = this.createRenderTree(newList, '');
        if (currentTreeNode && factor.branchType === '1') {
            // 获取当前展开当前的节点
            this.currentOpenTreeNode.push(currentTreeNode);
        }
        this.entryBranch = {
            countType: '0',
            factorCode: '',
            branchName: '',
            branchType: '',
            entryCode: '',
        };
        // 回调数据
        this.$emit('set-branch-data', this.riskEntryBranchs);
    }

    // 组装数据
    createDynamicConfigPO(paramParentBranchNo: any) {
        // 条目信息
        let entryControl = this.entryControl;
        let entryBranchPojo = this.entryBranch;
        let branchName = '';
        let factorCode = '';
        let countType = entryBranchPojo.countType;
        let branchType = '';
        let entryCode = entryControl.entryCode;
        let parentBranchNo = paramParentBranchNo;
        let branchNo = this.branchNo;
        let entryCalFacDyParam = '0';
        let entryCalculateFactorDynamicParam = '';
        // 创建组时
        if (entryBranchPojo.factorCode === '') {
            branchName = '';
            factorCode = '';
            branchType = '1';
        } else {
            branchName = entryBranchPojo.branchName.trim()
                ? entryBranchPojo.branchName
                : this.branchEnum[entryBranchPojo.factorCode].entryCalculateFactorName;
            factorCode = entryBranchPojo.factorCode;
            branchType = '0';
        }
        let newEntryBranchPojo = {};
        // newEntryBranchPojo = {
        //     branchName: branchName,
        //     factorCode: factorCode,
        //     countType: countType,
        //     branchType: branchType,
        //     entryCode: entryCode,
        //     parentBranchNo: parentBranchNo,
        //     branchNo: branchNo,
        //     entryCalFacDyParam: entryCalFacDyParam,
        //     label: DictionConstUtil.RiskEntryBranchSplicingType[countType] + ' ' + (branchName || ''),
        //     entryCalculateFactorDynamicParam: entryCalculateFactorDynamicParam,
        // };
        if (countType == '4') {
            if (branchName) {
                this.yh_message_warn('绝对值组分支,不能选择计算因子,已自动过滤掉计算因子配置');
            }
            newEntryBranchPojo = {
                branchName: '',
                factorCode: '',
                countType: countType,
                branchType: branchType,
                entryCode: entryCode,
                parentBranchNo: parentBranchNo,
                branchNo: branchNo,
                entryCalFacDyParam: entryCalFacDyParam,
                label: DictionConstUtil.RiskEntryBranchSplicingType[countType],
                entryCalculateFactorDynamicParam: entryCalculateFactorDynamicParam,
            };
        } else {
            newEntryBranchPojo = {
                branchName: branchName,
                factorCode: factorCode,
                countType: countType,
                branchType: branchType,
                entryCode: entryCode,
                parentBranchNo: parentBranchNo,
                branchNo: branchNo,
                entryCalFacDyParam: entryCalFacDyParam,
                label: DictionConstUtil.RiskEntryBranchSplicingType[countType] + ' ' + (branchName || ''),
                entryCalculateFactorDynamicParam: entryCalculateFactorDynamicParam,
            };
        }
        this.branchNo += 1;

        return newEntryBranchPojo;
    }

    /**
     * 根据分支序号 查找 配置项
     */
    searchBranchConfig(branchNo: any, field: any) {
        let value =
            this.riskEntryBranchs.find(item => {
                return item.entryBranch.branchNo === branchNo;
            }) || {};
        if (!field) {
            return value;
        } else if (field === 'entryBranch') {
            return value.entryBranch || {};
        } else if (field === 'entryBranchConfigs') {
            return value.entryBranchConfigs || [];
        }
    }

    /**
     * 列表组装成树形集合
     */
    createTreeAdoptList(orginalList: any, orginalParentBranchNo: any) {
        let newList = [];
        for (let i = 0; i < orginalList.length; i++) {
            let entryBranch = orginalList[i].entryBranch;
            if (entryBranch.parentBranchNo !== orginalParentBranchNo) {
                continue;
            }
            if (orginalList.find((item: any) => item.entryBranch.parentBranchNo === entryBranch.branchNo)) {
                entryBranch.children = this.createTreeAdoptList(orginalList, entryBranch.branchNo);
                newList.push(entryBranch);
            } else {
                entryBranch.children = [];
                newList.push(entryBranch);
            }
        }
        return newList;
    }

    /**
     * 验证配置 并生成计算方式信息
     */
    verifyBranchConfig(values: any) {
        let des = '(';
        var flag = false;
        for (let i = 0; i < values.length; i++) {
            if (values[i].countType === '4') {
                flag = true;
                des += '+';
            }
            des += { '0': '+', '1': '-', '2': '*', '3': '/', '4': '|' }[values[i].countType];
            if (i === 0 && (values[i].countType === '2' || values[i].countType === '3')) {
                this.yh_message_warn('分支配置不合理，算法无法解析。请检查 ... ...');
                break;
            }
            if (values[i].children && values[i].children.length > 0) {
                des += this.verifyBranchConfig(values[i].children);
            } else {
                des += values[i].branchName;
            }
            if (flag) {
                des += '|';
                flag = false;
            }
        }
        des += ')';
        return des;
    }

    /**
     * 创建树节点
     */
    createRenderTree(treeList: any, val: any) {
        return treeList.map((item: any) => {
            let countName = DictionConstUtil.RiskEntryBranchSplicingType[item.countType];
            let title = countName + ' ' + item.branchName;
            // 渲染时记录所有的父级节点
            if (item.branchType === '1') {
                this.allParentTreeNodes.push(String(item.branchNo));
            }
            if (item.children && item.children.length > 0) {
                return item;
            }

            let calcFactorList = this.branchEnum[item.factorCode] || {};
            let color = 'blue';
            if (calcFactorList.existDynamicCfg) {
                let params = calcFactorList.dynamicCfg || [];

                // let pv = (item.entryCalculateFactorDynamicParam || '').split(',').filter(ic => (ic ? true : false));
                let pv = (item.entryCalculateFactorDynamicParam || '').split(',');

                let paramValue = {};
                for (let value of pv) {
                    if (value && value.includes(':')) {
                        paramValue[value.substr(0, value.indexOf(':'))] = value.substr(value.indexOf(':') + 1);
                    }
                }
                for (let v of params) {
                    if (!paramValue[v]) {
                        color = 'orange';
                        break;
                    }
                }
            }
            return item;
        });
    }

    // 点击节点事件
    onSelectConfigTree(keys: any): void {
        let currentSelectCalcFactor: any = {};
        this.renderBoundCount = this.renderBoundCount + 1;
        // 点击2次
        if (this.currentTreeNode === keys.branchNo) {
            this.entryBranchConfigTree = JSON.parse(JSON.stringify(this.entryBranchConfigTree)); //
            this.currentTreeNode = null;
            this.entryBranch = {
                branchName: '',
                factorCode: '',
                countType: '0',
                branchType: '',
                entryCode: '',
            };
            this.investGroupTypeValue = '';
            this.investGroupType = {};
            this.originalConfigList = [];
            this.optionalInvestGroupType = [];
            this.originalRenderTree = this.handleRenderTree(this.originalConfigList);
            this.originalRenderTreeShow = [];
            this.templateCode = '';
            this.BranchDataSource = [];
        } else {
            // 点击一次
            if (keys) {
                let factor = this.searchBranchConfig(keys.branchNo, 'entryBranch');
                this.currentSelectCalcFactor = this.branchEnum[factor.factorCode] || {};
                this.entryBranch = {
                    branchName: factor.branchType === '0' ? factor.branchName : '',
                    factorCode: factor.branchType === '0' ? factor.factorCode : '',
                    countType: factor.countType,
                    branchType: factor.branchType,
                    entryCode: '',
                    label: DictionConstUtil.RiskEntryBranchSplicingType[factor.countType] + ' ' + (factor.branchName || ''),
                };
                this.currentTreeNode = keys.branchNo;
            } else {
                this.currentSelectCalcFactor = {};
                this.entryBranch = {
                    branchName: '',
                    factorCode: '',
                    countType: '0',
                    branchType: '',
                    entryCode: '',
                };
                this.currentTreeNode = '';
            }
            this.onSelectOne();
        }
    }

    // 点击时调用的数据
    onSelectOne() {
        this.investGroupType.value =
            (this.searchBranchConfig(this.currentTreeNode, 'entryBranchConfigs').find((item: any) => item.groupType !== 'groupType') || {})
                .groupType || '';
        this.investGroupType.optional = (this.currentSelectCalcFactor.boundTypes || []).sort(
            (a: any, b: any) => b.replace(/[^0-9]/gi, '') - a.replace(/[^0-9]/gi, '')
        );

        this.optionalInvestGroupType = this.investGroupType.optional || [];
        this.BoundType = DictionConstUtil.BoundType;
        this.originalConfigList = [];
        let groupSet = this.searchBranchConfig(this.currentTreeNode, 'entryBranchConfigs');
        if (groupSet.length > 0) {
            this.investGroupTypeValue = (groupSet.find((item: any) => item.groupType !== 'groupType').groupType || '').toString();
        } else {
            this.investGroupTypeValue = '';
        }

        // 设置初始的configId
        this.handleSetInitConfigId(groupSet);
        // 对范围集合进行分组 即this.OriginalBoundConfigPojo赋值
        this.handlegGroupBoundType(groupSet);
        // 设置默认的范围属性
        this.originalRenderTree = [];
        if (this.optionalInvestGroupType.length > 0) {
            if (!this.investGroupTypeValue) {
                this.investGroupTypeValue = this.optionalInvestGroupType[0];
            }
            this.OriginalBoundConfigPojo[this.investGroupTypeValue] = this.createEnptyGroup(
                this.OriginalBoundConfigPojo[this.investGroupTypeValue],
                this.investGroupTypeValue
            );
            this.originalRenderTree = this.handleGetRenderTree(this.OriginalBoundConfigPojo[this.investGroupTypeValue]);
        } else {
            this.originalRenderTree = [];
        }
        for (let i = 0; i < this.originalRenderTree.length; i++) {
            this.originalRenderTree[i].webgroupType = this.investGroupTypeValue;
        }
        // 华泰开放分支模板动态维度
        this.originList = this.BoundCfgs.filter(item => item.boundType === this.investGroupTypeValue).sort(
            (a, b) => a.boundCode.replace(/[^0-9]/gi, '') - b.boundCode.replace(/[^0-9]/gi, '')
        );
        this.templateCode = '';
        this.BranchDataSource = this.BranchData.filter((item: any) => item.boundType === this.investGroupTypeValue);
        this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);
        // 清除范围配置项
        this.resBoundData();
        // 原先的
        this.originalConfigList = this.handleInsetBoundCofig();
        // 赋值
        this.handleBoundConfig();
    }

    // 清空数据
    resBoundData() {
        this.fundDynamicGroupBounds = {
            // 证券范围配置项
            boundCode: '-1',
            boundValues: [],
            compareType: '',
            boundValueNames: [],
            boundGroupValid: false,
            parentId: 0,
            configId: 0,
            separateValid: false, // 是否同申报
            sqlSpliceType: '0', // sql拼接符
            groupType: '', // 范围配置组控制类型
            webSqlType: '', // 辅助字段 拼接符
            webBoundName: '', // 辅助字段 证券范围名称
            webCompareType: '', // 辅助字段 比较方向名称
            webBoundvalue: '', // 辅助字段 范围选择值
            boundExtend: '', // 范围模板5额外配置字段
            showBoundExtend: false,
            webgroupType: '',
        };
    }

    // 右边显示  通过范围渲染tree
    returnTreeData(originalRenderTree: any, investGroupTypeValue: any) {
        let newList = [];
        if (originalRenderTree.length > 0) {
            for (let i = 0; i < originalRenderTree.length; i++) {
                if (originalRenderTree[i].webgroupType == investGroupTypeValue) {
                    newList.push(originalRenderTree[i]);
                }
            }
        } else {
            newList = [];
        }
        return newList;
    }

    // 给右边范围赋值
    handleInsetBoundCofig(): any {
        let riskEntryBranchs = this.riskEntryBranchs;
        for (let i = 0; i < riskEntryBranchs.length; i++) {
            if (riskEntryBranchs[i].entryBranch.branchNo === Number(this.currentTreeNode)) {
                return riskEntryBranchs[i].entryBranchConfigs;
            }
        }
    }

    // 分支名称
    changBranchName(val: any): void {
        if (val) {
            this.entryBranch.branchName = this.branchEnum[val].entryCalculateFactorName;
        } else {
            this.entryBranch.branchName = '';
        }
    }

    // 添加分支模块
    handleAddTemplate() {
        let templateCode = this.entryBranch.templateCode;
        if (!templateCode) {
            return;
        }
        this.$axios.get('/entry/template/branch/query/' + templateCode).then((res: any) => {
            let templateBranch = res.riskEntryBranchs;
            if (!templateBranch) {
                return;
            }
            // 当前选择的树节点
            let currentTreeNode = this.currentTreeNode ? parseInt(this.currentTreeNode) : null;
            let factor = this.searchBranchConfig(currentTreeNode, 'entryBranch');
            // 获取下一分序号
            let branchNo = this.branchNo - 1;
            // 判断添加节点位置
            if (currentTreeNode && factor.branchType === '1') {
                for (let i = 0; i < templateBranch.length; i++) {
                    templateBranch[i].entryBranch.branchNo += branchNo;
                    templateBranch[i].entryBranch.label =
                        DictionConstUtil.RiskEntryBranchSplicingType[templateBranch[i].entryBranch.countType] +
                        ' ' +
                        (templateBranch[i].entryBranch.branchName || '');
                    if (templateBranch[i].entryBranch.parentBranchNo === 0) {
                        templateBranch[i].entryBranch.parentBranchNo = currentTreeNode;
                    } else {
                        templateBranch[i].entryBranch.parentBranchNo += branchNo;
                    }
                    this.branchNo = templateBranch[i].entryBranch.branchNo;
                }
            } else {
                for (let i = 0; i < templateBranch.length; i++) {
                    templateBranch[i].entryBranch.branchNo += branchNo;
                    templateBranch[i].entryBranch.label =
                        DictionConstUtil.RiskEntryBranchSplicingType[templateBranch[i].entryBranch.countType] +
                        ' ' +
                        (templateBranch[i].entryBranch.branchName || '');
                    if (templateBranch[i].entryBranch.parentBranchNo === 0) {
                    } else {
                        templateBranch[i].entryBranch.parentBranchNo += branchNo;
                    }
                    this.branchNo = templateBranch[i].entryBranch.branchNo;
                }
            }
            this.branchNo += 1;
            this.riskEntryBranchs = this.riskEntryBranchs.concat(templateBranch);
            let riskEntryBranchs = JSON.parse(JSON.stringify(this.riskEntryBranchs));
            let newList = this.createTreeAdoptList(riskEntryBranchs, 0);
            // 执行配置公式生成方式
            this.calculateShowLogic = this.verifyBranchConfig(newList);
            // 节点渲染 默认展开所有的节点
            this.entryBranchConfigTree = this.createRenderTree(newList, '');
            if (currentTreeNode && factor.branchType === '1') {
                // 获取当前展开当前的节点
                this.currentOpenTreeNode.push(currentTreeNode);
            }
            // 回调数据
            this.$emit('set-branch-data', this.riskEntryBranchs);
        });
    }

    // 保存
    handleSaveConfig(): void {
        let currentTreeNode = this.currentTreeNode;
        if (!currentTreeNode) {
            this.yh_message_warn('请选择节点进行操作');
            return;
        }
        if (!this.verifyBranchConfig1()) {
            return;
        }
        let factor = this.searchBranchConfig(currentTreeNode, 'entryBranch');
        if (factor.branchType === '1') {
            this.yh_message_warn('组分支不支持修改');
            return;
        }
        let riskEntryBranchs = this.riskEntryBranchs;
        let entryBranchPojo = this.entryBranch;
        for (let i = 0; i < riskEntryBranchs.length; i++) {
            if (riskEntryBranchs[i].entryBranch.branchNo === Number(currentTreeNode)) {
                riskEntryBranchs[i].entryBranch.branchName = entryBranchPojo.branchName;
                riskEntryBranchs[i].entryBranch.factorCode = entryBranchPojo.factorCode;
                riskEntryBranchs[i].entryBranch.countType = entryBranchPojo.countType;
                riskEntryBranchs[i].entryBranch.label =
                    DictionConstUtil.RiskEntryBranchSplicingType[entryBranchPojo.countType] + ' ' + (entryBranchPojo.branchName || '');
                break;
            }
        }
        riskEntryBranchs = JSON.parse(JSON.stringify(riskEntryBranchs));
        let newList = this.createTreeAdoptList(riskEntryBranchs, 0);
        // 执行配置公式生成方式
        this.calculateShowLogic = this.verifyBranchConfig(newList);
        // 节点渲染
        this.entryBranchConfigTree = this.createRenderTree(newList, '');
        // 回调数据
        this.$emit('set-branch-data', this.riskEntryBranchs);
    }

    /**
     * 验证配置 检验参数是否正确
     */
    verifyBranchConfig1() {
        // 证券范围信息
        let entryBranchPojo = this.entryBranch;
        if (entryBranchPojo.factorCode === '-1' || !entryBranchPojo.factorCode) {
            // 添加组时 目前无需验证
        } else {
            if (!entryBranchPojo.branchName || !entryBranchPojo.branchName.trim()) {
                this.yh_message_error('分支名称不可为空');
                return false;
            }
        }
        return true;
    }

    // 删除配置
    handleDelConfig(): void {
        let currentTreeNode = this.currentTreeNode;
        if (!currentTreeNode) {
            this.yh_message_error('请选择配置进行删除');
            return;
        }
        currentTreeNode = parseInt(currentTreeNode);
        let newList = this.queryChildrenNode(this.riskEntryBranchs, currentTreeNode);
        this.riskEntryBranchs = this.riskEntryBranchs.filter(item => !newList.includes(item.entryBranch.branchNo));
        this.renderBoundCount = this.renderBoundCount + 1;
        let riskEntryBranchs = JSON.parse(JSON.stringify(this.riskEntryBranchs));
        let newListEntry = this.createTreeAdoptList(riskEntryBranchs, 0);
        // 执行配置公式生成方式
        this.calculateShowLogic = this.verifyBranchConfig(newListEntry);
        // 节点渲染
        this.entryBranchConfigTree = this.createRenderTree(newListEntry, '');
        this.entryBranch = {
            branchName: '',
            factorCode: '',
            countType: '0',
            branchType: '',
            entryCode: '',
        };
        this.currentSelectCalcFactor = {};
        this.currentTreeNode = '';
        // 执行回调函数
        this.$emit('set-branch-data', this.riskEntryBranchs);
    }

    /**
     * 查询当前节点下的所有子节点
     */
    queryChildrenNode(orginalList: any, currentTreeNode: any) {
        let newList = [];
        newList.push(currentTreeNode);
        for (let i = 0; i < orginalList.length; i++) {
            let entryBranch = orginalList[i].entryBranch;
            if (entryBranch.parentBranchNo === currentTreeNode) {
                newList.push(entryBranch.branchNo);
                if (orginalList.find((item: any) => item.entryBranch.parentBranchNo === entryBranch.branchNo)) {
                    newList = newList.concat(this.queryChildrenNode(orginalList, entryBranch.branchNo));
                }
            }
        }
        return newList;
    }

    /**
     * 范围右边所有函数
     *
     *
     *
     */

    changInvestType() {
        // 获取可配置范围信息
        this.BranchDataSource = this.BranchData.filter((item: any) => item.boundType === this.investGroupTypeValue);
        // 华泰开放分支模板动态维度
        this.originList = this.BoundCfgs.filter(item => item.boundType === this.investGroupTypeValue).sort(
            (a, b) => a.boundCode.replace(/[^0-9]/gi, '') - b.boundCode.replace(/[^0-9]/gi, '')
        );
        this.handlegGroupBoundType(this.originalConfigList);
        if (this.optionalInvestGroupType.length > 0) {
            if (!this.investGroupTypeValue) {
                this.investGroupTypeValue = this.optionalInvestGroupType[0];
            }
            this.OriginalBoundConfigPojo[this.investGroupTypeValue] = this.createEnptyGroup(
                this.OriginalBoundConfigPojo[this.investGroupTypeValue],
                this.investGroupTypeValue
            );
            this.originalRenderTree = this.handleGetRenderTree(this.OriginalBoundConfigPojo[this.investGroupTypeValue]);
        } else {
            this.originalRenderTree = [];
        }
        for (let i = 0; i < this.originalRenderTree.length; i++) {
            this.originalRenderTree[i].webgroupType = this.investGroupTypeValue;
        }
        this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);
        this.currentConfigSeparateValid = false;
        // 清除范围配置项
        this.handleOriginalBoundConfig('-1');
    }

    changeCategory(val: any) {
        let a = val.find((item: any) => {
            return item == '-1';
        });
        if (val.length == 0) {
            this.Category = false;
            this.CategoryAll = false;
        } else if (a == '-1') {
            this.Category = false;
            this.CategoryAll = true;
        } else {
            this.Category = true;
            this.CategoryAll = false;
        }
    }

    lookBranchData() {
        this.branchVisible = true;
        this.getBoundDetail(this.investGroupTypeValue, '', this.boundPage);
    }

    // 获取范围预览数据
    getBoundDetail(boundType: any, param: any, paging: any): void {
        this.loading = true;
        this.$axios
            .post('/original/bound/detail/list', {
                boundType: boundType,
                param: param,
                paging: paging,
            })
            .then((res: any) => {
                this.loading = false;
                if (res.list) {
                    // eslint-disable-next-line no-return-assign
                    res.list.forEach((item: any, i: any) => (item.rowKey = String(i)));
                    this.dataSource = res.list;
                    this.boundPage.total = res.total;
                }
            })
            .catch(() => {
                this.loading = false;
            });
    }

    // 关闭
    oepnDialog() {
        this.searchValue = '';
        this.branchVisible = false;
    }

    // 翻页
    boundPageChange(): void {
        this.getBoundDetail(this.investGroupTypeValue, this.searchValue, this.boundPage);
    }

    // 查询
    searchBound(): void {
        this.boundPage.currentPage = 1;
        this.getBoundDetail(this.investGroupTypeValue, this.searchValue, this.boundPage);
    }

    // 证券范围配置下拉列表框改变时 触发该事件
    private handleOriginalBoundConfig(val: string): void {
        this.fundDynamicGroupBounds.dynamicCode = '';
        this.fundDynamicGroupBounds.separateValid = false;
        this.fundDynamicGroupBounds.groupType = '0';
        this.fundDynamicGroupBounds.boundCode = val;
        this.fundDynamicGroupBounds.compareType = '';
        this.fundDynamicGroupBounds.boundValues = [];
        this.fundDynamicGroupBounds.boundValueNames = [];
        this.currentConfigSeparateValid = false; // 当前范围是否支持同申报
        this.clearBoundFormColumn(this.webShowType);
        this.webShowType = '';
        this.compareTypes = [];
        this.separateValid = false;
        this.boundValueShow = '';
        if (val !== '-1') {
            let stockBoundConfig = this.BoundCfgs.find(item => item.boundCode === val);
            this.currentConfigSeparateValid = stockBoundConfig.separateValid; // 当前范围是否支持同申报
        }
        if (this.fundDynamicGroupBounds.boundCode === '-1') {
            this.fundDynamicGroupBounds.boundGroupValid = true;
            this.webShowType = '';
            this.compareTypes = [];
            this.separateValid = false;
        } else {
            this.fundDynamicGroupBounds.boundGroupValid = false;
            this.originList.forEach((element: any) => {
                if (element.boundCode === val) {
                    this.compareTypes = element.webDirections;
                    this.webShowType = element.webShowType;
                    if (this.webShowType === '0') {
                        // 多选
                        this.handleShowWebShow(val);
                    } else if (this.webShowType === '4') {
                        // 单选
                        this.handleShowWebShow(val);
                    }
                }
            });
        }
        this.$forceUpdate();
    }

    // 触发下拉框 webShowType === '0'
    showTypeFocusEvent(): void {
        this.boundValueSearchInput = '';
        this.dictsTemp = this.dicts;
        (this.$refs as any).showTypeDown.showPanel();
    }

    // 范围配置下拉框搜索
    boundValueSearch(): void {
        this.dictsTemp =
            this.boundValueSearchInput !== ''
                ? this.dicts.filter(element => {
                      return element.dictKey.indexOf(this.boundValueSearchInput) > -1 || element.dictKeyName.indexOf(this.boundValueSearchInput) > -1;
                  })
                : this.dicts;
    }

    // 多选框类型---下拉框选择改变处理
    handleBoundValueChange(checkedData: any): void {
        setTimeout(() => {
            (this.$refs as any).showTypeDown.showPanel();
        }, 10);
        let i = 0;
        this.boundValueShow = '';
        this.fundDynamicGroupBounds.boundValueNames = [];
        checkedData.forEach(element => {
            this.dicts.forEach(item => {
                if (element === item.dictKey) {
                    this.boundValueShow = this.boundValueShow + element + '(' + item.dictKeyName + ')';
                    this.fundDynamicGroupBounds.boundValueNames.push(item.dictKeyName);
                }
            });
            i++;
            if (i < checkedData.length) {
                this.boundValueShow = this.boundValueShow + ',';
            }
        });
    }

    handleBoundValueChangeOne(checkedData: any): void {
        let i = 0;
        this.boundValueShow = '';
        this.fundDynamicGroupBounds.boundValueNames = [];
        checkedData.forEach(element => {
            this.dicts.forEach(item => {
                if (element === item.dictKey) {
                    this.boundValueShow = this.boundValueShow + element + '(' + item.dictKeyName + ')';
                    this.fundDynamicGroupBounds.boundValueNames.push(item.dictKeyName);
                }
            });
            i++;
            if (i < checkedData.length) {
                this.boundValueShow = this.boundValueShow + ',';
            }
        });
    }

    // 计数器类型
    handleBoundValueChange1(num: number): void {
        this.webShowType == '1' && (num = Math.round(num));
        this.fundDynamicGroupBounds.boundValues = [];
        this.fundDynamicGroupBounds.boundValueNames = [];
        this.fundDynamicGroupBounds.boundValues.push(num.toString());
        this.fundDynamicGroupBounds.boundValueNames.push(num.toString());
    }

    // 大数据穿梭框--弹框
    selectKeyValue2Click(): void {
        this.editLargeDataDialog = this.editLargeDataDialog.getAddDialog('');
        this.transValuesShow = this.fundDynamicGroupBounds.boundValueNames.toString();
    }

    // 选择器类型
    handleBoundValueChange3(value: any): void {
        this.fundDynamicGroupBounds.boundValues = [];
        this.fundDynamicGroupBounds.boundValueNames = [];
        this.fundDynamicGroupBounds.boundValues.push(value);
        this.dictsTemp.forEach(ele => {
            if (ele.dictKey === value) {
                this.fundDynamicGroupBounds.boundValueNames.push(ele.dictKeyName);
                return;
            }
        });
    }

    //  根据证券范围配置编号获取 展示SQL
    handleShowWebShow(boundCode: any) {
        if (boundCode === '-1') {
            return;
        }
        this.dicts = [];
        return new Promise(resolve => {
            this.$axios.get('/original/showSelect/' + boundCode).then(
                (res: any) => {
                    if (res) {
                        this.dicts = res;
                        this.dictsTemp = this.dicts;
                        resolve('success'); //
                    }
                },
                () => {
                    this.dicts = [];
                    this.dictsTemp = [];
                    resolve('fail');
                }
            );
        });
    }
    // 日期类型
    @Watch('boundValueDate')
    handleBoundValueChange2() {
        const date = this.boundValueDate;
        this.fundDynamicGroupBounds.boundValues = [];
        this.fundDynamicGroupBounds.boundValueNames = [];
        this.fundDynamicGroupBounds.boundValues.push(date);
        this.fundDynamicGroupBounds.boundValueNames.push(date);
    }

    // 穿梭框数据
    getRightTranData(values: any): any {
        let arr: any[] = [];
        for (let i = 0; i < values.boundValues.length; i++) {
            arr.push({ dictKey: values.boundValues[i], dictKeyName: values.boundValueNames[i] });
        }
        return arr;
    }

    // 将范围属性表单字段置空
    clearBoundFormColumn(webShowType: string) {
        if (webShowType === '1' || webShowType === '5') {
            this.form.boundValueNum = undefined;
        } else if (webShowType === '4') {
            this.boundValueSelect = '';
        } else if (webShowType === '3') {
            this.boundValueDate = '';
        }
    }

    // sql拼接字符串
    handleSqlSpliceType(value: string): void {
        this.fundDynamicGroupBounds.sqlSpliceType = value.split(' ')[0];
    }

    // 单独控制
    changSeparateValid() {
        this.fundDynamicGroupBounds.separateValid = this.separateValid;
        if (this.separateValid && this.fundDynamicGroupBounds.compareType == '') {
            this.fundDynamicGroupBounds.compareType = '4';
        }
    }

    handleAddConfigRight(): void {
        this.fundDynamicGroupBounds.webgroupType = this.investGroupTypeValue;
        let dynamicOriginalConfigPO: dynamicDataReqVO = JSON.parse(JSON.stringify(this.fundDynamicGroupBounds));
        let isAdopt = this.verifySingleConfig(dynamicOriginalConfigPO);
        if (!isAdopt) {
            return;
        }
        if (!this.investGroupTypeValue) {
            this.yh_message_warn('请先选择范围属性组进行配置');
            return;
        }
        // 当前选择的树节点
        let currentTreeNode = this.currentTreeNodeR;
        let obcp = this.OriginalBoundConfigPojo[this.investGroupTypeValue];
        let nodeValue = obcp.children.find(item => item.configId === Number(currentTreeNode));
        let boundGroupValid = false;
        if (nodeValue) {
            boundGroupValid = nodeValue.boundGroupValid;
        } else {
            boundGroupValid = false;
        }
        if (currentTreeNode && boundGroupValid) {
            dynamicOriginalConfigPO.parentId = Number(currentTreeNode);
        } else {
            dynamicOriginalConfigPO.parentId = obcp.configId;
        }

        let boundPo = this.createDynamicConfigPOR(dynamicOriginalConfigPO);
        obcp.children.push(boundPo);
        // 获取当前展开当前的节点 若果为父节点则展开
        if (currentTreeNode && boundGroupValid) {
            this.currentOpenTreeNodeR.push(currentTreeNode);
        }
        if (this.OriginalBoundConfigPojo[this.investGroupTypeValue].children) {
            if (this.OriginalBoundConfigPojo[this.investGroupTypeValue].children.length > 0) {
                this.OriginalBoundConfigPojo[this.investGroupTypeValue].children.forEach((el: any) => {
                    el.webgroupType = this.investGroupTypeValue;
                });
            }
        }
        this.OriginalBoundConfigPojo[this.investGroupTypeValue] = this.createEnptyGroup(
            this.OriginalBoundConfigPojo[this.investGroupTypeValue],
            this.investGroupTypeValue
        );
        this.originalRenderTree = this.handleGetRenderTree(this.OriginalBoundConfigPojo[this.investGroupTypeValue]);
        // this.originalRenderTree = this.handleGetRenderTree(obcp);
        this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);
        this.onHandleSettingValue();
        // 清除范围配置项
        this.handleOriginalBoundConfig('-1'); // -1相当于是重新进行清空操作
    }

    /**
     * 创建空的对象 组
     */
    createEnptyGroup(singleOBCP, investGroupTypeValue) {
        let returnValue = singleOBCP;
        if (!singleOBCP) {
            let dynamicOriginalBoundConfigPO = {
                boundCode: '-1',
                parentId: 0,
                groupType: investGroupTypeValue,
                specialBranch: false,
                sqlSpliceType: '0',
            };
            returnValue = this.createDynamicConfigPOR(dynamicOriginalBoundConfigPO);
            returnValue.children = [];
            return returnValue;
        }
        // 设置是否显示范围额外配置信息
        if (returnValue.children !== undefined && returnValue.children.length > 0) {
            returnValue.children.forEach(item => {
                item.showBoundExtend = this.isShowBoundExtend(item.boundCode);
            });
        }
        return returnValue;
    }

    createDynamicConfigPOR(dynamicOriginalBoundConfigPO: any) {
        // 证券范围信息
        let boundCode = '';
        let boundValues = [];
        let compareType = '';
        let boundValueNames = [];
        let boundGroupValid = true;
        let configId = this.configId;
        let parentId = dynamicOriginalBoundConfigPO.parentId;
        let separateValid = false;
        let sqlSpliceType = dynamicOriginalBoundConfigPO.sqlSpliceType;
        let groupType = dynamicOriginalBoundConfigPO.groupType ? dynamicOriginalBoundConfigPO.groupType : '0';
        let specialBranch = false;

        let webSqlType = DictionConstUtil.SqlSplicingType[dynamicOriginalBoundConfigPO.sqlSpliceType]; // 辅助字段 拼接符
        let webBoundName = ''; // 辅助字段 证券范围名称
        let webCompareType = ''; // 辅助字段 比较方向名称
        let webBoundvalue = ''; // 辅助字段 范围选择值
        // 添加空组时
        if (dynamicOriginalBoundConfigPO.boundCode === '-1') {
            compareType = '4';
            boundGroupValid = true;
            separateValid = false;
            specialBranch = dynamicOriginalBoundConfigPO.specialBranch;
        } else if (dynamicOriginalBoundConfigPO.separateValid === true) {
            // 添加同申报
            boundCode = dynamicOriginalBoundConfigPO.boundCode;
            compareType = '4';
            boundGroupValid = false;
            separateValid = true;
            let stockBoundConfig = this.BoundCfgs.find(item => item.boundCode === dynamicOriginalBoundConfigPO.boundCode);
            webBoundName = stockBoundConfig.boundName; // 辅助字段 证券范围名称
            webBoundvalue = '单独控制'; // 辅助字段 范围选择值
        } else {
            // fundDynamicGroupBounds.compareType
            boundCode = dynamicOriginalBoundConfigPO.boundCode;
            boundValues = dynamicOriginalBoundConfigPO.boundValues;
            compareType = dynamicOriginalBoundConfigPO.compareType || '';
            boundValueNames = dynamicOriginalBoundConfigPO.boundValueNames;
            boundGroupValid = false;
            separateValid = false;
            let stockBoundConfig = this.BoundCfgs.find(item => item.boundCode === dynamicOriginalBoundConfigPO.boundCode);
            webBoundName = stockBoundConfig.boundName; // 辅助字段 证券范围名称
            webCompareType = DictionConstUtil.CompareDirection[dynamicOriginalBoundConfigPO.compareType]; // 辅助字段 比较方向名称
            webBoundvalue = ['1', '5', '3'].includes(stockBoundConfig.webShowType)
                ? dynamicOriginalBoundConfigPO.boundValues
                : dynamicOriginalBoundConfigPO.boundValueNames; // 辅助字段 范围选择值
        }

        let showBoundExtend = this.isShowBoundExtend(boundCode);
        let newDynamicOriginalBoundConfigPO = {
            boundCode: boundCode,
            boundValues: boundValues,
            compareType: compareType,
            boundValueNames: boundValueNames,
            boundGroupValid: boundGroupValid,
            parentId: parentId,
            configId: configId,
            separateValid: this.separateValid, // 是否同申报
            sqlSpliceType: sqlSpliceType, // sql拼接符
            groupType: groupType, // 范围配置组控制类型
            specialBranch: specialBranch,

            webSqlType: webSqlType, // 辅助字段 拼接符
            webBoundName: webBoundName, // 辅助字段 证券范围名称
            webCompareType: webCompareType, // 辅助字段 比较方向名称
            webBoundvalue: webBoundvalue, // 辅助字段 范围选择值
            // boundExtend:boundExtend,
            webgroupType: this.investGroupTypeValue,
            showBoundExtend: showBoundExtend,
        };
        this.configId += 1;
        return newDynamicOriginalBoundConfigPO;
    }

    /**
     * 是否展示范围额外配置信息
     */
    isShowBoundExtend(boundCode) {
        this.resolveKey = '';
        if (boundCode === undefined || boundCode === '') {
            return false;
        } else {
            let data = this.BoundCfgs.filter(item => item.boundCode === boundCode)[0] || {};
            if (!data.resolveKey) {
                return;
            }
            if (data.resolveKey.indexOf('|') !== '-1' && data.resolveKey.split('|')[0] == '6') {
                this.resolveKey = data.resolveKey.split('|')[0];
            } else if (['5', '6'].includes(data.resolveKey)) {
                // this.resolveKey = '5';
                this.resolveKey = data.resolveKey;
            }
            return this.resolveKey === '5' || this.resolveKey === '6';
            // return (this.BoundCfgs.filter(item => item.boundCode === boundCode)[0] || {}).resolveKey === '5';
        }
    }

    // 刷新范围
    async refreshAllBranchTemplate() {
        // let BranchData: any = [];
        this.BranchData = await DictionConstUtil.FNBranchBoundTemplateRefresh();
        this.BranchDataSource = this.BranchData.filter((item: any) => item.boundType === this.investGroupTypeValue);
        this.yh_message_success('范围模版数据刷新成功');
    }

    /**
     * 设置初始的config
     */
    handleSetInitConfigId(stockBound) {
        let configId = 1;
        stockBound = stockBound || [];
        for (let i = 0; i < stockBound.length; i++) {
            if (stockBound[i].configId > configId) {
                configId = stockBound[i].configId;
            }
        }
        configId += 1;
        this.configId = configId;
    }

    /**
     * 根据stockBound中的groupType 对范围属性类型进行分组
     */
    handlegGroupBoundType(stockBound) {
        // 对范围增加一些属性用于范围展示
        this.handleStockBoundShow(stockBound);
        let groupPojo = {};
        for (let i = 0; i < stockBound.length; i++) {
            if (stockBound[i].parentId === 0) {
                groupPojo[stockBound[i].groupType] = stockBound[i];
            }
        }
        for (let key in groupPojo) {
            let resultList = [];
            // 创建普通范围集合
            this.handleSearchGroupLost(stockBound, groupPojo[key].configId, resultList);
            groupPojo[key].children = resultList;
        }
        this.OriginalBoundConfigPojo = groupPojo;
    }

    /**
     * 查找 configId 下的 parentId
     */
    handleSearchGroupLost(orginalList, configId, resultList) {
        for (let i = 0; i < orginalList.length; i++) {
            if (orginalList[i].parentId === configId) {
                resultList.push(orginalList[i]);
                if (orginalList.find(item => item.parentId === orginalList[i].configId)) {
                    this.handleSearchGroupLost(orginalList, orginalList[i].configId, resultList);
                }
            }
        }
    }

    // 增加一个空数据
    onHandleSettingValue() {
        let OriginalBoundConfigPojo = JSON.parse(JSON.stringify(this.OriginalBoundConfigPojo));
        let newList = [];
        /*
            "2": "银行属性组配置",
            "3": "证券属性组配置",
            "4": "对手方属性组配置",
            "5":"银行查看组配置", //银行属性组配置 下的子属性
            "6":"证券查看组配置", //证券属性组配置 下的子属性
            "7":"对手方查看组配置",//对手方属性组配置 下的子属性
         */
        let transform = {
            '2': '5',
            '3': '6',
            '4': '7',
        };
        for (let key in OriginalBoundConfigPojo) {
            let temp = OriginalBoundConfigPojo[key];

            let tempList = temp.children;
            for (let i = 0; i < tempList.length; i++) {
                if (tempList[i].specialBranch) {
                    tempList[i].groupType = transform[temp.groupType] || '0';
                    if (!tempList.find(item => item.parentId === tempList[i].configId)) {
                        tempList.splice(i, 1);
                        i--;
                    }
                }
            }
            if (tempList.length > 0) {
                temp.children = [];
                newList.push(temp);
                newList = newList.concat(tempList);
            }
        }
        this.originalConfigList = [];
        this.originalConfigList = newList;
        this.handleBoundConfig();

        // return newList;
    }

    /**
     * 对范围增加一些属性用于范围展示
     */
    handleStockBoundShow(stockBound) {
        for (let i = 0; i < stockBound.length; i++) {
            if (stockBound[i].boundGroupValid) {
                // stockBound[i].webgroupType = this.investGroupTypeValue;
                stockBound[i].webgroupType = '';
                stockBound[i].webSqlType = DictionConstUtil.SqlSplicingType[stockBound[i].sqlSpliceType]; // 辅助字段 拼接符
                stockBound[i].webBoundName = ''; // 辅助字段 证券范围名称
                stockBound[i].webCompareType = ''; // 辅助字段 比较方向名称
                stockBound[i].webBoundvalue = ''; // 辅助字段 范围选择值
            } else {
                let stockBoundConfig = this.BoundCfgs.find(item => item.boundCode === stockBound[i].boundCode);
                if (stockBoundConfig === undefined) {
                    this.yh_message_warn('范围指标配置数据加载中！');
                    return;
                }
                stockBound[i].webgroupType = this.investGroupTypeValue;
                stockBound[i].webSqlType = DictionConstUtil.SqlSplicingType[stockBound[i].sqlSpliceType]; // 辅助字段 拼接符
                stockBound[i].webBoundName = stockBoundConfig.boundName; // 辅助字段 证券范围名称
                // 同申报
                if (stockBound[i].separateValid) {
                    stockBound[i].webCompareType = ''; // 辅助字段 比较方向名称
                    stockBound[i].webBoundvalue = '单独控制'; // 辅助字段 范围选择值
                    // eslint-disable-next-line brace-style
                }
                // 数字输入框
                else if (stockBoundConfig.webShowType === '5' || stockBoundConfig.webShowType === '1') {
                    stockBound[i].webCompareType = DictionConstUtil.CompareDirection[stockBound[i].compareType]; // 辅助字段 比较方向名称
                    stockBound[i].webBoundvalue = stockBound[i].boundValues; // 辅助字段 范围选择值
                    // eslint-disable-next-line brace-style
                }
                // 其他的信息
                else {
                    stockBound[i].webCompareType = DictionConstUtil.CompareDirection[stockBound[i].compareType]; // 辅助字段 比较方向名称
                    stockBound[i].webBoundvalue = stockBound[i].boundValueNames; // 辅助字段 范围选择值
                }
            }
        }
    }

    /**
     * 范围配置数据赋值
     */
    handleBoundConfig(): void {
        let riskEntryBranchs = this.riskEntryBranchs;
        for (let i = 0; i < riskEntryBranchs.length; i++) {
            if (riskEntryBranchs[i].entryBranch.branchNo === Number(this.currentTreeNode)) {
                riskEntryBranchs[i].entryBranchConfigs = this.originalConfigList;
            }
        }
        this.riskEntryBranchs = riskEntryBranchs;
        this.$emit('set-branch-data', this.riskEntryBranchs);
    }

    // 校验配置的范围信息
    verifySingleConfig(dynamicOriginalConfigPO: any): boolean {
        // 添加空组时
        if (dynamicOriginalConfigPO.boundCode === '-1') {
            return true;
        } else if (dynamicOriginalConfigPO.separateValid === true) {
            return true;
        } else {
            if (!dynamicOriginalConfigPO.boundValues || dynamicOriginalConfigPO.boundValues.length === 0) {
                // || this.separateValid === true
                if (this.separateValid === true) {
                    return true;
                } else {
                    this.yh_message_info('未配置范围属性的值');
                    return false;
                }
            }
            if (!dynamicOriginalConfigPO.compareType) {
                this.yh_message_info('未配置比较方向');
                return false;
            }
            return true;
        }
    }

    // 将集合创建成树
    handleRenderTree(stockBound: any) {
        let newOrginalPojo = JSON.parse(JSON.stringify(stockBound));
        let configId = newOrginalPojo.configId;
        let list = newOrginalPojo.children;
        let treeList = this.createTreeList(newOrginalPojo, 0);
        treeList.forEach(item => {
            item.showBoundExtend = this.isShowBoundExtend(item.boundCode);
        });
        let value = this.handleRenderListTree(treeList);
        return value;
    }

    handleGetRenderTree(orginalPojo: any) {
        let newOrginalPojo = JSON.parse(JSON.stringify(orginalPojo));
        let configId = newOrginalPojo.configId;
        let list = newOrginalPojo.children;
        let treeList = [];
        this.createTreeAdoptListR(list, configId, treeList);
        let treeListRender = this.handleRenderListTree(treeList);
        return treeListRender;
    }

    /**
     * 列表组装成树形集合
     */
    createTreeAdoptListR(orginalList, configId, newList) {
        for (let i = 0; i < orginalList.length; i++) {
            if (orginalList[i].parentId === configId) {
                if (orginalList.map(item => item.parentId).includes(orginalList[i].configId) && orginalList[i].boundGroupValid === true) {
                    let childrenNewList = [];
                    this.createTreeAdoptListR(orginalList, orginalList[i].configId, childrenNewList);
                    orginalList[i].children = childrenNewList;
                }
                newList.push(orginalList[i]);
            }
        }
    }

    // 列表组装成树形集合
    createTreeList(orginalList: any, configId: any): any {
        let newList = [];
        for (let i = 0; i < orginalList.length; i++) {
            if (orginalList[i].parentId === configId) {
                if (orginalList.find(item => item.parentId === orginalList[i].configId)) {
                    orginalList[i].children = this.createTreeList(orginalList, orginalList[i].configId);
                }
                newList.push(orginalList[i]);
            }
        }
        return newList;
    }

    // 范围配置 树形集合转化成渲染树(显示树)
    handleRenderListTree(treeList: any) {
        return treeList.map(item => {
            // 处理节点名称
            // debugger;

            let sqlSpliceTypeName = this.conditionRelation[item.sqlSpliceType];
            let boundName = '';
            let compareTypeName = '';
            let boundValueNames = '';
            // 组配置
            if (item.boundGroupValid) {
                boundName = '';
                compareTypeName = '';
                boundValueNames = '';
            } else if (item.separateValid) {
                for (let i = 0; i < this.originList.length; i++) {
                    if (item.boundCode == this.originList[i].boundCode) {
                        boundName = this.originList[i].boundName;
                    }
                }
                // boundName = orgCfg.boundName;
                compareTypeName = this.CompareDirection[item.compareType] || '';
                boundValueNames = '单独控制';
            } else {
                for (let i = 0; i < this.originList.length; i++) {
                    if (item.boundCode == this.originList[i].boundCode) {
                        boundName = this.originList[i].boundName;
                    }
                }
                // boundName = orgCfg.boundName;
                compareTypeName = this.CompareDirection[item.compareType] || '';
                boundValueNames = item.boundValueNames || item.boundValues || '';
            }
            boundName = item.webBoundName;
            // let title = sqlSpliceTypeName + ' ' + boundName + ' ' + compareTypeName + ' ' + boundValueNames;
            let title = item.webSqlType + ' ' + item.webBoundName + ' ' + item.webCompareType + ' ' + boundValueNames;
            // 渲染时记录所有的父级节点
            if (item.boundGroupValid) {
                this.allParentTreeNodeR.push(String(item.configId));
            }
            // 存在子节点
            if (item.children && item.children.length > 0) {
                item.children = this.handleRenderListTree(item.children);
            }
            return Object.assign(item, {
                label: title,
                configId: String(item.configId),
            });
        });
    }

    // 点击节点
    handleBoundNodeClick(keys: any) {
        this.fundDynamicGroupBounds = {};
        this.webShowType = '';
        this.compareTypes = [];
        if (!keys.configId) {
            return;
        }

        if (this.currentTreeNodeR === keys.configId) {
            this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);
            this.currentTreeNodeR = '';
            this.transValuesShow = '';
            this.separateValid = false; // 是否支持同申报
            this.rightTranData = [];
            // 第二次点击
            this.fundDynamicGroupBounds = {
                dynamicCode: '',
                boundCode: '-1',
                boundValues: [],
                compareType: '',
                boundValueNames: [],
                boundGroupValid: true,
                parentId: 0,
                configId: 0,
                separateValid: false,
                sqlSpliceType: '0',
                groupType: this.investGroupTypeValue,
            };
            this.sqlSpliceType = '0 并且';
        } else {
            // 第一次点击
            // fundDynamicGroupBounds.compareType
            // this.investGroupTypeValue = keys.webgroupType;
            this.currentTreeNodeR = keys.configId;
            let orgBound;
            // let orgBound = this.originalConfigList.find(item => String(item.configId) === keys.configId);
            for (let i = 0; i < this.originalConfigList.length; i++) {
                if (this.originalConfigList[i].configId == keys.configId) {
                    orgBound = this.originalConfigList[i];
                }
            }
            if (!orgBound) {
                orgBound = keys;
            }
            this.sqlSpliceType = orgBound.sqlSpliceType + ' ' + this.Dict.conditionRelation[orgBound.sqlSpliceType];
            orgBound.webgroupType = this.investGroupTypeValue;
            this.fundDynamicGroupBounds = orgBound;
            if (this.fundDynamicGroupBounds.boundCode == '' || this.fundDynamicGroupBounds.boundCode == undefined) {
                this.fundDynamicGroupBounds.boundCode = '-1';
                this.fundDynamicGroupBounds.compareType = '';
            }
            if (keys.separateValid) {
                this.currentConfigSeparateValid = true; // 当前范围是否支持同申报
            } else {
                this.currentConfigSeparateValid = false; // 当前范围是否支持同申报
            }
            this.separateValid = keys.separateValid;

            if (orgBound.boundGroupValid) {
                // 组配置
                this.webShowType = '';
                this.compareTypes = [];
                // this.separateValid = false;
            } else {
                let orgCfg: any = null;
                // let orgCfg = this.originList.find(item => item.boundCode === orgBound.boundCode);
                for (let i = 0; i < this.originList.length; i++) {
                    if (orgBound.boundCode === this.originList[i].boundCode) {
                        orgCfg = this.originList[i];
                    }
                }
                this.webShowType = orgCfg.webShowType;
                this.compareTypes = orgCfg.webDirections || [];
                // this.separateValid = orgCfg.separateValid;
                // 如果为下拉列表时 需要加载下拉列表数据
                if (this.webShowType === '0') {
                    this.handleShowWebShow(orgBound.boundCode).then(() => {
                        this.handleBoundValueChangeOne(this.fundDynamicGroupBounds.boundValues);
                    });
                } else if (this.webShowType === '4') {
                    this.handleShowWebShow(orgBound.boundCode).then(() => {
                        this.boundValueSelect = this.fundDynamicGroupBounds.boundValues.toString();
                    });
                } else if (this.webShowType === '1') {
                    this.form.boundValueNum = parseInt(this.fundDynamicGroupBounds.boundValueNames.toString());
                } else if (this.webShowType === '5') {
                    this.form.boundValueNum = parseFloat(this.fundDynamicGroupBounds.boundValueNames.toString());
                } else if (this.webShowType === '2') {
                    this.rightTranData = this.fundDynamicGroupBounds.boundValues.map((dictKey, i) => ({
                        dictKey,
                        dictKeyName: this.fundDynamicGroupBounds.boundValueNames[i],
                    }));
                    if (this.fundDynamicGroupBounds.boundValueNames) {
                        this.transValuesShow = this.fundDynamicGroupBounds.boundValueNames.toString();
                    }
                    this.currentConfigSeparateValid = true;
                } else if (this.webShowType === '3') {
                    this.boundValueDate = this.fundDynamicGroupBounds.boundValueNames.toString();
                }
            }
        }
    }

    // 更新配置项
    handleUpdateConfig(): void {
        if (!this.currentTreeNodeR) {
            this.yh_message_warn('请选择节点进行操作');
            return;
        }
        let index;
        let orgBound = this.originalConfigList.find((item, i) => {
            index = i;
            return String(item.configId) === this.currentTreeNodeR;
        });
        if (orgBound.boundGroupValid) {
            this.yh_message_warn('组节点不允许进行修改');
            return;
        }
        // 证券范围信息
        let dynamicOriginalBoundConfigPO = JSON.parse(JSON.stringify(this.fundDynamicGroupBounds));
        let isAdopt = this.verifySingleConfig(dynamicOriginalBoundConfigPO);
        if (!isAdopt) {
            return;
        }
        // 设置 configId 和 parentId
        dynamicOriginalBoundConfigPO.configId = orgBound.configId;
        dynamicOriginalBoundConfigPO.parentId = orgBound.parentId;
        this.originalConfigList.splice(index, 1, dynamicOriginalBoundConfigPO);
        this.handlegGroupBoundType(this.originalConfigList);
        if (this.OriginalBoundConfigPojo[this.investGroupTypeValue].children) {
            if (this.OriginalBoundConfigPojo[this.investGroupTypeValue].children.length > 0) {
                this.OriginalBoundConfigPojo[this.investGroupTypeValue].children.forEach((el: any) => {
                    el.webgroupType = this.investGroupTypeValue;
                });
            }
        }
        this.OriginalBoundConfigPojo[this.investGroupTypeValue] = this.createEnptyGroup(
            this.OriginalBoundConfigPojo[this.investGroupTypeValue],
            this.investGroupTypeValue
        );
        this.originalRenderTree = this.handleGetRenderTree(this.OriginalBoundConfigPojo[this.investGroupTypeValue]);
        this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);
        // 回调函数
        this.handleBoundConfig();
        this.handleOriginalBoundConfig('-1');
    }

    // 删除证券范围配置
    handleDeleteConfig(): void {
        if (!this.currentTreeNodeR) {
            this.yh_message_warn('请选择节点进行删除');
            return;
        }
        let newList = [];
        newList.push(Number(this.currentTreeNodeR));
        this.handleSearchConfigId(this.originalConfigList, Number(this.currentTreeNodeR), newList);
        for (let i = 0; i < this.originalConfigList.length; i++) {
            if (newList.includes(this.originalConfigList[i].configId)) {
                this.originalConfigList.splice(i, 1);
                i--;
            }
        }
        this.handlegGroupBoundType(this.originalConfigList);
        if (this.OriginalBoundConfigPojo[this.investGroupTypeValue].children) {
            if (this.OriginalBoundConfigPojo[this.investGroupTypeValue].children.length > 0) {
                this.OriginalBoundConfigPojo[this.investGroupTypeValue].children.forEach((el: any) => {
                    el.webgroupType = this.investGroupTypeValue;
                });
            }
        }
        this.OriginalBoundConfigPojo[this.investGroupTypeValue] = this.createEnptyGroup(
            this.OriginalBoundConfigPojo[this.investGroupTypeValue],
            this.investGroupTypeValue
        );
        this.originalRenderTree = this.handleGetRenderTree(this.OriginalBoundConfigPojo[this.investGroupTypeValue]);
        this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);

        // 回调函数
        this.onHandleSettingValue();
        this.handleBoundConfig();
        this.handleOriginalBoundConfig('-1');
    }

    // 查找 configId 下的范围  用于删除节点
    handleSearchConfigId(orginalList: any, configId: number, newList: any[]) {
        for (let i = 0; i < orginalList.length; i++) {
            if (orginalList[i].parentId === configId) {
                if (orginalList.map((item: any) => item.parentId).includes(orginalList[i].configId)) {
                    this.handleSearchConfigId(orginalList, orginalList[i].configId, newList);
                }
                newList.push(orginalList[i].configId);
            }
        }
    }

    // 大数据弹窗确认
    editLargeDataDialogConfirm(): void {
        const rightData = (this.$refs.trans as any).getRightAllData();
        this.fundDynamicGroupBounds.boundValues = XEUtils.map(rightData, item => item.dictKey);
        this.fundDynamicGroupBounds.boundValueNames = XEUtils.map(rightData, item => item.dictKeyName);
        this.transValuesShow = this.fundDynamicGroupBounds.boundValueNames.toString();
        this.editLargeDataDialog.visible = false;
    }

    // 右边添加模块
    handleAddTemplateR(): void {
        let templateCode = this.templateCode;
        if (!templateCode) {
            return;
        }
        this.$axios.get('/entry/template/bound/query/' + templateCode).then((res: any) => {
            let templateBranch = res.riskEntryBranchs;
            if (!templateBranch || templateBranch.length === 0) {
                return;
            }
            // 当前选择的树节点
            let currentTreeNode = this.currentTreeNodeR;
            this.OriginalBoundConfigPojo[this.investGroupTypeValue] = this.createEnptyGroup(
                this.OriginalBoundConfigPojo[this.investGroupTypeValue],
                this.investGroupTypeValue
            );
            let obcp = this.OriginalBoundConfigPojo[this.investGroupTypeValue];

            // 模板数据
            let value = templateBranch[0].entryBranchConfigs;
            if (value.length === 0) {
                return;
            }
            for (let i = 0; i < value.length; i++) {
                value[i].webgroupType = this.investGroupTypeValue;
            }
            let valueCf = value.find((item: any) => item.groupType !== '0');
            let cpConfigId = valueCf.configId;
            let chValue = value.filter((item: any) => item.groupType === '0');
            let setNodeValue = obcp.children.find(item => item.configId === Number(this.currentTreeNodeR)) || {};
            let boundGroupValid;
            if (setNodeValue.boundGroupValid == true) {
                boundGroupValid = true;
            } else {
                boundGroupValid = false;
            }
            for (let i = 0; i < chValue.length; i++) {
                chValue[i].boundCode = chValue[i].boundGroupValid ? '-1' : chValue[i].boundCode;
                let cfi = chValue[i].configId;
                chValue[i] = this.createDynamicConfigPOR(chValue[i]);
                chValue[i].configId = cfi;
            }
            let configId = this.configId;
            this.configId = configId;
            // 判断添加节点位置
            if (this.currentTreeNodeR && boundGroupValid) {
                for (let i = 0; i < chValue.length; i++) {
                    chValue[i].configId += configId;
                    if (chValue[i].parentId === cpConfigId) {
                        chValue[i].parentId = parseInt(this.currentTreeNodeR);
                    } else {
                        chValue[i].parentId += configId;
                    }
                    this.configId = chValue[i].configId;
                }
            } else {
                for (let i = 0; i < chValue.length; i++) {
                    chValue[i].configId += configId;
                    if (chValue[i].parentId === cpConfigId) {
                        chValue[i].parentId = obcp.configId;
                    } else {
                        chValue[i].parentId += configId;
                    }
                    this.configId = chValue[i].configId;
                }
            }
            this.configId += 1;
            obcp.children = obcp.children.concat(chValue);
            this.originalRenderTree = this.handleGetRenderTree(obcp);
            this.originalRenderTreeShow = this.returnTreeData(this.originalRenderTree, this.investGroupTypeValue);
            this.currentOpenTreeNode = [...this.currentOpenTreeNodeR];
            if (currentTreeNode && boundGroupValid) {
                // 获取当前展开当前的节点
                this.currentOpenTreeNodeR.push(currentTreeNode);
            }
            this.onHandleSettingValue();
            // 清除范围配置项
            this.handleOriginalBoundConfig('-1'); // -1相当于是重新进行清空操作
            // 赋值
            this.handleBoundConfig();
        });
    }
}
</script>
<style lang="scss" scoped>
.baranch {
    color: #222;

    .search-wrap {
        padding-bottom: 5px;

        .my-dropdown {
            width: 200px;
            max-height: 200px;
            overflow: auto;
            border: 1px solid #eee;
            border-radius: 1px;
        }
    }

    .col-wrap:nth-child(1) {
        padding-right: 5px;
    }

    .col-wrap:nth-child(2) {
        padding-right: 5px;
    }

    .border-box {
        padding-left: 5px;
        border: 1px solid #eee;
        background: #f5f5f5;
        border-radius: 5px;
        border-bottom: none;
    }

    .border-box:nth-child(3) {
        border-bottom: 1px solid #eee;
    }

    .tree-box {
        overflow: auto;
        height: 282px;
        background: #fff;
        border: 1px solid #eee;
    }

    .showdialog {
        height: 600px;
    }

    .showdialog /deep/ .el-dialog .el-dialog__body {
        height: 480px;
        max-width: none;
    }

    & /deep/ .el-dialog .el-dialog__body {
        max-height: 100vh;
    }
}

/deep/ .el-button--mini,
.el-button--mini.is-round {
    padding: 6px 10px;
}

/deep/ .el-tree {
    width: fit-content;
    .el-tree-node.is-current > .el-tree-node__content {
        background: transparent;
        & > span:last-child {
            background: #bae7ff;
            color: #415159;
        }
    }
    .el-tree-node__content {
        background: transparent;
        &:hover {
            & > span:last-child {
                background: #e6f7ff;
                color: #415159;
            }
        }
    }
}

/deep/ .editDialog .el-dialog .el-dialog__body {
    height: 460px;
}

/deep/ .el-tree__empty-text {
    position: static;
}

/deep/ .el-select__tags {
    flex-wrap: nowrap;
}
/deep/ .el-dialog .el-dialog__body {
    height: 480px;
    max-width: none;
}
</style>
